﻿using System.Web.Mvc;
using DNT.RavenQA.Core.Extensions;
using StructureMap;

namespace DNT.RavenQA.Web.Infrastructure.IoC
{
    public class InjectingActionInvoker : ControllerActionInvoker
    {
        private readonly IContainer _container;

        public InjectingActionInvoker(IContainer container)
        {
            container.EnsureIsNotNull("container");
            _container = container;
        }

        protected override FilterInfo GetFilters(ControllerContext controllerContext,
                                                 ActionDescriptor actionDescriptor)
        {
            var info = base.GetFilters(controllerContext, actionDescriptor);

            foreach (var filter in info.ActionFilters)
                _container.BuildUp(filter);

            return info;
        }
    }
}